package com.hsl.test.utils;

import com.hsl.test.aop.TAutowired;
import com.hsl.test.aop.TService;

import java.sql.SQLException;

/**
 * @author hsl
 * @Data 2021/12/14
 * @Desc 事务管理器
 */
@TService
public class TransactionManager {

    @TAutowired
    private ConnectionUtil connectionUtil;

    /**
     * 开启事务
     *
     * @throws SQLException
     */
    public void beginTransaction() throws SQLException {
        connectionUtil.getCurrentConn().setAutoCommit(Boolean.FALSE);
    }

    /**
     * 提交事务
     *
     * @throws SQLException
     */
    public void commit() throws SQLException {
        connectionUtil.getCurrentConn().commit();
    }

    /**
     * 回滚事务
     *
     * @throws SQLException
     */
    public void rollback() throws SQLException {
        connectionUtil.getCurrentConn().rollback();
    }
}
